package com.noreply.springlearning.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author noreply
 * @description
 * @datetime 2021/10/18 15:34
 */
@Aspect
public class AspectJTest {
    @Pointcut("execution(* *.test()) ")
    public void test(){}

    @Before("test()")
    public void before() {
        System.out.println("before");
    }

    @Before("test()")
    public void after() {
        System.out.println("after");
    }

    @Around("test()")
    public Object around(ProceedingJoinPoint joinPoint) {
        System.out.println("around before");
        Object o = null;
        try {
            o = joinPoint.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("around after");
        }
        return o;
    }

}
